<?php
/**
 * Created by PhpStorm.
 * User: lx
 * Date: 2020/1/14
 * Time: 19:09
 */
namespace app\api\controller;

use app\api\model\MtShopApplyExam;
use app\command\controller\Common;
use app\util\ReturnCode;

class Apply extends Base
{
    /**
     * 合作信息审核提交
     */
    public function examInfoUpload(){
        $rule = [
            "trueName" => "require|max:20",
            "userID" => "require|number",
            "userTel" => "require|number|max:15",
            "idCard" => "require|number|max:18",
            "shopName" => "require|max:20",
            "shopArea" => "require",
            "shopType" => "require|number", // 1个人 2企业
            "idCardProve" => "require",
            "idCardBack" => "require",
            "license" => "require",
        ];
        $msg = [];
        $data = $this->request->post();
        $verifiRes = (new Common())->VerifiString($rule, $msg, $data);
        if ($verifiRes['code'] == 2) {
            return $this->error(ReturnCode::EMPTY_PARAMS, $verifiRes['msg']);
        }
        $data['cTime'] = time();
        $res = (new MtShopApplyExam())->insert($data,true);
        if(!$res){
            return $this->error(ReturnCode::DB_SAVE_ERROR,"入库失败");
        }
        return $this->success("入库成功");
    }

    /**
     * 合作审核信息图片上传
     * @return mixed|void
     */
    public function examImgUpload(){
        if(!$this->request->file("shopExam")){
            return $this->error(ReturnCode::EMPTY_PARAMS,"请上传文件");
        }
        $uploadType = $this->request->get("uploadType");
        if(!$uploadType){
            return $this->error(ReturnCode::EMPTY_PARAMS,"缺少参数uploadType");
        }
        switch ($uploadType){
            case 1:
                $filePath = config("apiadmin.SHOP_APPLY_EXAM")."prove/";
                break;
            case 2:
                $filePath = config("apiadmin.SHOP_APPLY_EXAM")."back/";
                break;
            case 3:
                $filePath = config("apiadmin.SHOP_APPLY_EXAM")."license/";
                break;
        }
        $res = (new Common())->upload($filePath,"shopExam");
        return $res;
    }
}